package com.hkts.naturalgas.dictionaries.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.web.bind.annotation.*;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hkts.naturalgas.dictionaries.service.IHktsEnvironmentTemperatureService;
import com.hkts.naturalgas.dictionaries.entity.HktsEnvironmentTemperature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2021-10-18
 */
@RestController
@RequestMapping("/instrumentdata/hktsEnvironmentTemperature")
public class HktsEnvironmentTemperatureController {
    private final Logger logger = LoggerFactory.getLogger(HktsEnvironmentTemperatureController.class);

    @Autowired
    public IHktsEnvironmentTemperatureService iHktsEnvironmentTemperatureService;

    /**
     * 分页查询数据
     *
     * @param page                       分页信息
     * @param hktsEnvironmentTemperature 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsEnvironmentTemperaturePageList")
    public Result<Object> getHontUserList(Page<HktsEnvironmentTemperature> page, HktsEnvironmentTemperature hktsEnvironmentTemperature) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsEnvironmentTemperatureService.selectPage(page, hktsEnvironmentTemperature)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsEnvironmentTemperature 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsEnvironmentTemperatureSave")
    public Result<Object> hktsEnvironmentTemperatureSave(@RequestBody HktsEnvironmentTemperature hktsEnvironmentTemperature) {
        QueryWrapper<HktsEnvironmentTemperature> query = Wrappers.query();
        query.lambda().eq(HktsEnvironmentTemperature::getTableId,hktsEnvironmentTemperature.getId());
        HktsEnvironmentTemperature one = iHktsEnvironmentTemperatureService.getOne(query);
        one.setSettingTemperature(hktsEnvironmentTemperature.getSettingTemperature());
        iHktsEnvironmentTemperatureService.saveOrUpdate(one);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsEnvironmentTemperatureGetById")
    public Result<Object> hktsEnvironmentTemperatureGetById(String id) {
        HktsEnvironmentTemperature byId = iHktsEnvironmentTemperatureService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsEnvironmentTemperatureDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsEnvironmentTemperatureService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsEnvironmentTemperatureBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsEnvironmentTemperatureService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }


}
